//
//  WoDeViewController.m
//  黑土公社商户端
//
//  Created by 1 on 15/12/23.
//  Copyright © 2015年 刘成. All rights reserved.
//

#import "WoDeViewController.h"
#import "shangJiaXinXiViewController.h"
@interface WoDeViewController ()

@end

@implementation WoDeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的";
    self.view.backgroundColor = [UIColor blueColor];
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:106/255.0 green:221/255.0 blue:86/255.0 alpha:1.0]];
    self.titles = @[@"商家信息",@"我的代金劵",@"我的余额",@"我的退款",@"我的消息",@"在线客服",@"我的收藏",@"我的评论",@"常见问题",@"我是商家"];
    self.imageNames = @[@"wdshdz.png",@"wddjq.png",@"wdye.png",@"wdtk.png",@"wdxx.png",@"zxkf.png",@"wdsc.png",@"wdpl.png",@"cjwt.png",@"wssj.png"];
    
    wodeTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)style:UITableViewStyleGrouped];
    wodeTableView.delegate = self;
    wodeTableView.dataSource = self;
    wodeTableView.bounces=NO;
    wodeTableView.showsVerticalScrollIndicator = NO;
    
    [self tableViewHeaderView];
    [self.view addSubview:wodeTableView];
    
}
- (void)tableViewHeaderView {
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 110)];
    headerView.backgroundColor = [UIColor greenColor];
    UIButton *sexButton = [[UIButton alloc]initWithFrame:CGRectMake((kScreenWidth-70)/2, 20, 70, 70)];
    [sexButton setImage:[UIImage imageNamed:@"logo.png"] forState:UIControlStateNormal];
    [headerView addSubview:sexButton];
    UIButton *shezhiButton = [[UIButton alloc]initWithFrame:CGRectMake(kScreenWidth-20-10, 5, 20, 20)];
    [shezhiButton setImage:[UIImage imageNamed:@"sz.png"] forState:UIControlStateNormal];
    [headerView addSubview:shezhiButton];
    
    [wodeTableView setTableHeaderView:headerView];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark --- UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return _titles.count;
    }else{
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        static NSString *cellIdent = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
        }
        cell.textLabel.text = _titles[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        //        cell.imageView.image = [UIImage imageNamed:_imageNames[indexPath.row]];
        UIImage *icon = [UIImage imageNamed:_imageNames[indexPath.row]];
        CGSize itemSize = CGSizeMake(30, 30);
        UIGraphicsBeginImageContextWithOptions(itemSize, NO, 0.0);
        CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
        [icon drawInRect:imageRect];
        cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return cell;
    }
    if (indexPath.section == 1) {
        static NSString *cellIdent = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
        }
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-120)/2, (cell.frame.size.height-20)/2, 120, 20)];
        label.text = @"客服 400－011-7777";
        label.font = [UIFont systemFontOfSize:12];
        [cell addSubview:label];
        return cell;
        
    }
    static NSString *cellIdent = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdent];
    }
    
    return cell;
    
}

// 计算cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 7;
    
}
// 设置header的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

// 处理ios8下uitable分割线不兼容
-(void)viewDidLayoutSubviews {
    if ([wodeTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [wodeTableView setSeparatorInset:UIEdgeInsetsMake(0,14,0,0)];
        [wodeTableView setSeparatorColor:TABLE_CELL_LINE_COLOR];
    }
    
    if ([wodeTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [wodeTableView setLayoutMargins:UIEdgeInsetsMake(0,14,0,0)];
    } 
}
//cell点击事件
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    if (indexPath.row == 0) {
//    shangJiaXinXiViewController *shangjiaxinxiVC = [[shangJiaXinXiViewController alloc]init];
//    [ self presentViewController:shangjiaxinxiVC animated: YES completion:nil];
//
//    }
//}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
